import { GUIComponent } from "../../../../com/mui/controls/GUIComponent";
import { ResouceConst } from "../../../component/gconst/ResouceConst";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { GLabel } from "../../../../com/mui/controls/GLabel";
import { FilterConst } from "../../../component/gconst/FilterConst";
import { GTextFormat } from "../../../common/GTextFormat";
import { FontUtil } from "../../../common/font/FontUtil";
import { ScaleBitmap } from "../../../../com/mui/display/ScaleBitmap";
type int = number;
//class BaseProgressBar
    
    export  class BaseProgressBar extends GUIComponent
    {
        constructor(arg1: string=null, arg2: Boolean=false)
        {
            super();
            this._bgClass = arg1;
            this._isScale = arg2;
            return;
        }

        public setText(arg1: string): void
        {
            this._label.text = arg1;
            return;
        }

        public setProgressPosition(arg1: number, arg2: number): void
        {
            if (this._progressBar) 
            {
                this._progressBar.x = arg1;
                this._progressBar.y = arg2;
            }
            return;
        }

        public setLabelPosition(arg1: number, arg2: number): void
        {
            if (this._label) 
            {
                this._label.x = arg1;
                this._label.y = arg2;
            }
            return;
        }

        public resize(arg1: number, arg2: number): void
        {
            this.x = (arg1 - this.width) / 2;
            this.y = (arg2 - this.height) / 2;
            return;
        }

        public get progressBarBg(): Object /* flash.display.Bitmap */
        {
            return this._progressBarBg;
        }

        public set progressBarBg(arg1: Object /* flash.display.Bitmap */)
        {
            this._progressBarBg = arg1;
            return;
        }

        public get showPercentText(): Boolean
        {
            return this._showPercentText;
        }

        public set showPercentText(arg1: Boolean)
        {
            this._showPercentText = arg1;
            return;
        }

        public /* override */ setSize(arg1: number, arg2: number): void
        {
            super.setSize(arg1, arg2);
            if (this._progressBarBg) 
            {
                this._progressBarBg.width = arg1;
                this._progressBarBg.height = arg2;
            }
            this._backBarWidth = arg1;
            if (this._label) 
            {
                this._label.width = arg1;
                this._label.height = arg2;
            }
            if (this._isScale && this._processScaleBmp) 
            {
                this._processScaleBmp.setSize(_width - this._progressBar.x * 2, 8);
                this._progressBar.bitmapData = this._processScaleBmp.bitmapData;
            }
            return;
        }

        public get isScale(): Boolean
        {
            return this._isScale;
        }

        public set isScale(arg1: Boolean)
        {
            this._isScale = arg1;
            return;
        }

        public get showProgressText(): Boolean
        {
            return this._showProgressText;
        }

        public set showProgressText(arg1: Boolean)
        {
            this._showProgressText = arg1;
            if (arg1 == false) 
            {
                this._label.text = "";
            }
            return;
        }

        public set progressBarClass(arg1: string)
        {
            this._progressBarClass = arg1;
            if (this._isScale) 
            {
                if (this._progressBar.bitmapData) 
                {
                    this._progressBar.bitmapData.dispose();
                }
                this._processScaleBmp = ResouceConst.getScaleBitmap(arg1);
                this._processScaleBmp.setSize(_width - this._progressBar.x * 2, 8);
                this._progressBar.bitmapData = this._processScaleBmp.bitmapData;
            }
            else 
            {
                this._progressBar.bitmapData = GlobalClass.getBitmapData(arg1);
            }
            return;
        }

        public get progressBarClass(): string
        {
            return this._progressBarClass;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            if (this._bgClass && !(this._bgClass == null)) 
            {
                this._progressBarBg = ResouceConst.getScaleBitmap(this._bgClass);
                this.addChild(this._progressBarBg);
            }
            this._progressBar = new Object /* flash.display.Bitmap */();
            this.addChild(this._progressBar);
            this._label = new GLabel();
            this._label.name = "label";
            this._label.text = "";
            this._label.mouseChildren = false;
            this._label.mouseEnabled = false;
            this._label.textField.filters = [FilterConst.glowFilter];
            this._label.autoSize = flash.text.TextFieldAutoSize.CENTER;
            this._label.setStyle("textFormat", new GTextFormat(FontUtil.songtiName, 12, 16580298));
            this.addChild(this._label);
            return;
        }

        public /* override */ dispose(arg1: Boolean=true): void
        {
            return;
        }

        public setValue(arg1: number, arg2: number, arg3: number=1): void
        {
            var loc1=0;
            this._value = arg1;
            this._totalValue = arg2;
            if (arg1 > arg2) 
            {
                if (arg1 > 0 && arg2 > 0) 
                {
                    this._progressBar.scaleX = arg3;
                }
                else 
                {
                    this._progressBar.scaleX = 0;
                }
            }
            else 
            {
                this._progressBar.scaleX = arg3 * arg1 / arg2;
            }
            if (this._showProgressText) 
            {
                if (this._showPercentText) 
                {
                    if (arg2 != 0) 
                    {
                        if ((loc1 = Math.ceil(arg1 / arg2 * 100)) > 100) 
                        {
                            loc1 = 100;
                        }
                        this._label.text = loc1 + "%";
                    }
                    else 
                    {
                        this._label.text = "0%";
                    }
                }
                else 
                {
                    this._label.text = arg1 + "/" + arg2;
                }
            }
            return;
        }

        public get value(): number
        {
            return this._value;
        }

        public get totalValue(): number
        {
            return this._totalValue;
        }

        protected /* var */_progressBarClass: string;

        protected /* var */_processScaleBmp: ScaleBitmap;

        public /* var */_progressBar: Object /* flash.display.Bitmap */;

        protected /* var */_bgClass: string;

        protected /* var */_progressBarBg: Object /* flash.display.Bitmap */;

        protected /* var */_label: GLabel;

        protected /* var */barWidth: int;

        protected /* var */_showProgressText: Boolean=true;

        protected /* var */_showPercentText: Boolean=false;

        /* internal */ /* var */_isScale: Boolean=false;

        /* internal */ /* var */_backBarWidth: number;

        protected /* var */_totalValue: number;

        protected /* var */_value: number;
    }
